import Vue from 'vue';

const globalProvideSymbol = Symbol();

const globalContext = Vue.observable({
  headHeight: 0,
  menuWidth: 0,
  scrollTop: 0,
  scrollContentRef: null,
  setHeadHeight(headHeight) {
    this.headHeight = headHeight;
  },
  setMenuWidth(menuWidth) {
    this.menuWidth = menuWidth;
  },
  setScrollTop(y = 0) {
    this.scrollTop = y;
    if (this.scrollContentRef) {
      if (this.scrollContentRef.scrollTop !== y) {
        this.scrollContentRef.scrollTop = y;
      }
    }
  },
  setScrollContentRef(scrollContentRef) {
    this.scrollContentRef = scrollContentRef;
  }
});

export const useGlobalContext = () => {
  return globalContext;
};
